@extends('app')



@section('content')
    @component('form.form')

        @include('form.input',[
            'label' => '名称',
            'name'  => 'title',
            'val'   => $model->title??''
        ])

        @include('form.textarea',[
            'label' => '详情',
            'name'  => 'description',
            'val'   => $model->description,
        ])

        @include('form.uploadImages',[
            'label' => '图集',
            'name'  => 'img',
            'val'   => isset($model->img)?array_column($model->img->toArray(),'url'):[],
            'checked'=> $model->cover??'',
        ])

        @include('form.tabs',[
            'label' => '标签',
            'name'  => 'tabs',
            'val'   => isset($model->tabs)?(explode(',',$model->tabs)):['美女']
        ])

        {{--提交按钮组件--}}
        <div class="layui-form-item" style="position: fixed;background: #fff;box-shadow: 0 1px 5px 0 rgba(0,0,0,0.5);width: 100%;padding: 10px 0;margin: 0;left: 0; bottom: 0;text-align: center;">
            <button class="layui-btn" lay-filter="send" type="button" lay-submit>提交保存</button>
            <button class="layui-btn layui-btn-primary" type="button" id="cancel">取消返回</button>
        </div>

    @endcomponent
@endsection

@section('js')
<script>
    layui.use(['form','layedit'],function(){
        var form = layui.form;
        //监听提交
        form.on('submit(send)', function(data){
            data.field.cover = $('input.cover_img').val();//封面

            var tabs = $('#tags').find('span em');

            $('#tags span em').each(function(){
                data.field.tabs += $(this).text()+',';
            });

            console.log(data.field.tabs);
            $.post("/images/save", data.field, function (res) {
                if(res.code==0){
                    layer.msg(res.msg, {icon: 1,time: 1000},function () {
                        location.reload();
                    });
                }else{
                    layer.msg(res.msg, {icon: 2,time: 2000});
                }
            },'json');

            return false;
        });
    });
</script>
@endsection





























